package com.ejlchina.keno


fun  List<List<Int>>.randomPick(count: Int): List<List<Int>> {
    return this.shuffled().toList().take(count)
}

fun shortToLong(shortList: List<List<Int>>): List<List<Int>>{
    val resultList: MutableList<List<Int>> = mutableListOf()
    val count = shortList.size / 5
    for (index in 0 until count){
        resultList.add(shortList.subList(index * 5,index * 5 + 5).flatten().distinct().sorted())
    }
    return resultList
}

fun List<List<Int>>.shortToLongList(): List<List<Int>>{
    val resultList: MutableList<List<Int>> = mutableListOf()
    val countDivFive = size / 5
    for (index in 0 until countDivFive){
        resultList.add(subList(index * 5,index * 5 + 5).flatten().distinct().sorted())
    }
    return resultList
}

fun List<List<Int>>.shortToVerticalList(): List<List<Int>>{
    val resultList: MutableList<List<Int>> = mutableListOf()
    val countDivFive = size / 5
    for (index in 0 until countDivFive){
        val subFiveList = subList(index * 5, index * 5 + 5)
        repeat(5){
            val itemList = mutableListOf<Int>()
            for (item in subFiveList){
                itemList.add(item[it])
            }
            resultList.add(itemList)
        }
    }
    return resultList
}

fun List<List<Int>>.divideListToPageList(): MutableList<List<List<Int>>>{
    val resultList: MutableList<List<List<Int>>> = mutableListOf()
    val countDivFive = size / 5
    for (index in 0 until countDivFive){
        val subFiveList = subList(index * 5, index * 5 + 5)
        resultList.add(subFiveList)
    }
    return resultList
}

fun List<Int>.isAscending(): Boolean {
    for (i in 1 until size) {
        if (this[i] < this[i-1]) {
            return false
        }
    }
    return true
}